/**
 * Search list handling
 */
var np = {
	
	list : {},
	
	template : function() {
		debug.print("np.template");
		var ret = "\
<div class='pl-item'>\
	<div class='pl-artist'></div>\
	<div class='pl-title'></div>\
	<div class='pl-controls'>\
		<div class='removefrom-np'><a href='javascript:void(0);'>remove</a></div>\
		<div class='pl-cue-left'><a href='javascript:void(0);'>cue left</a></div>\
		<div class='pl-cue-right'><a href='javascript:void(0);'>cue right</a></div>\
	</div>\
</div>";
		return ret;		
	},
	
	add : function(item) {
		debug.print("np.add [item: " + item + "]");
		var pl = $("#np");
		this.list[item.id] = item;
		var pi = this.renderItem(item);
		pi.hide().slideDown(500);
	},
	
	addMultiple : function(items) {
		debug.print("np.addMultiple [items: " + items + "]");
		for (var i in items) {
			this.add(items[i])
		}
	},
	
	remove : function(dom, noeffect) {
		debug.print("np.remove [dom: " + dom + "]");
		var item = $(dom).data("video");
		delete this.list[item.id];
		if (noeffect === true) {
			$(dom).remove();
		} else {
			$(dom).slideUp(500, function(){
				$(dom).remove();
			});
		}
	},
	
	empty : function() {
		debug.print("np.empty");
		$("#np .pl-item").each(function() {
			np.remove(this, true);
		});
	},
	
	renderItem : function(item) {
		debug.print("np.renderItem [item: " + item + "]");
		var pl = $("#np");
		pl.append(this.template());
		var pi = pl.find(".pl-item:last");
		
		pi.data("video", item);
		
		pi.find(".pl-artist").text(item.artist);
		pi.find(".pl-title").text(item.title);
		pi.find(".removefrom-np").click(function() { controller.removeFromNp($(this).parent().parent(), item); });
		pi.find(".pl-cue-left").click(function() { controller.cue(0, item); });
		pi.find(".pl-cue-right").click(function() { controller.cue(1, item); });
		return pi;
	},
	
	count : function() {
		debug.print("np.count");
		return $("#np .pl-item").length;
	},
	
	getNext : function() {
		debug.print("np.getNext");
		return $("#np .pl-item:first");
	},
	
	getLast : function() {
		debug.print("np.getLast");
		return $("#np .pl-item:last");
	}
	
}